<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>打地鼠</title>
    <style>
        html {
            width: 100%;
            height: 100%;
        }

        body {
            margin: 0;
            width: 100%;
            height: 100%;
            background-image: url(image/bg.jpg);
            /* 鼠标样式 */
            cursor: url(image/cursor.png), auto;
            /* 不选中 */
            -moz-user-select: none;
        }

        table {
            /* 定宽居中 */
            width: 600px;
            height: 600px;
            margin: 0 auto;
        }

        td {
            height: 150px;
            background-image: url(image/hole.png);
            background-repeat: no-repeat;
            background-size: 120px 50px;
            /* 下对齐 */
            background-position: center bottom;
            /* 行元素对齐方式 */
            text-align: center;
            /* 改变高度从底部开始 */
            vertical-align: bottom;
        }

        img {
            width: 80px;
            height: 0px;
            position: relative;
            bottom: 10px;
        }

        .out {
            animation: mouseOut 0.5s both;
        }

        .in {
            animation: mouseIn 0.2s both;
        }

        #score {
            font-size: 30px;
            color: red;
        }

        /* 关键帧动画 */
        @keyframes mouseOut {
            from {
                height: 0;
            }

            to {
                height: 80px;
            }
        }

        @keyframes mouseIn {
            from {
                height: 80px;
            }

            to {
                height: 0;
            }
        }
    </style>
</head>

<body>
    <!-- 添加背景音乐 -->
    <audio src="audio/music.mp3" loop="loop" autoplay="autoplay"></audio>
    <audio id="dazhong" src="audio/dazhong.wav"></audio>
    <!-- 得分 -->
    <p id="score">得分: 0</p>
    <!-- 洞和老鼠 -->
    <table>
        <tr>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
        </tr>
        <tr>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
        </tr>
        <tr>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
        </tr>
        <tr>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
            <td><img src="image/mouse.png" alt=""></td>
        </tr>
    </table>
</body>

</html>
<script src="jquery.js"></script>
<script>
    //跳出一个老鼠
    function show(sdfghedfgvbn) {
        var random = Math.floor(Math.random() * 16);
        var img = $("img").get(random);
        $(img).removeClass("in").addClass("out");
        //1.5s之后消失
        setTimeout(function () {
            $(img).removeClass("out").addClass("in");
        }, 1500);
    }
    setInterval(function () {
        show();
        show();
        show();
    }, 3000);

    //切换锤子样式
    $("body").mousedown(function name(params) {
        $(this).css("cursor", "url(image/cursor-down.png),auto");
    }).mouseup(function name(params) {
        $(this).css("cursor", "url(image/cursor.png),auto");
    });

    //打地鼠
    var score = 0;
    $("img").click(function name(params) {
        //播放声音
        $("#dazhong")[0].load();
        $("#dazhong")[0].play();
        //中断声音
        // $("#dazhong")[0].load();
        
        //加分
        score = score + 10;
        $("#score").text("得分:"+ score);
        //敲中
        $(this).removeClass("out").addClass("in");
    });
</script>